<template>
  <div class="app-container">
    <MForm :fields="fields" :modelValue="modelValue" @submit="search" @cancel="search">
      <template #extra>
        <el-button type="warning" @click="exportNoCheck">导出</el-button>
      </template>
    </MForm>
    <el-table :data="tableData" border style="width: 100%" height="600px">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="center" type="index" width="60" />
      <el-table-column label="主管部门" align="center" prop="supervisoryUnit" />
      <el-table-column label="已参检数" align="center" prop="examineCount" />
      <el-table-column label="平均年检时长" align="center" prop="completionAvgCountTime" />
      <el-table-column label="平均办结时长" align="center" prop="completionAvgTime" />
      <el-table-column label="平均初审时长" align="center" prop="completionAvgTimeChu" />
    </el-table>

  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { fields, modelValue } from './config'
import { getComTimeList, exportComTimeList } from '@/api/yearCheck/index'

const tableData = ref([])
const total = ref()
// 搜索
const params = ref<any>({})

const search = (data: any) => {
  params.value = {
    ...params.value,
    ...data
  }
  getComTimeList(params.value).then(res => {
    tableData.value = res.data
  })
}

const exportNoCheck = () => {
  exportComTimeList(modelValue).then(res => {
    const blob = new Blob([res], {
      type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
    })
    const a = document.createElement('a')
    const URL = window.URL || window.webkitURL
    const herf = URL.createObjectURL(blob)
    a.href = herf
    a.download = '办结时间.xlsx'
    document.body.appendChild(a)
    a.click()
    document.body.removeChild(a)
    window.URL.revokeObjectURL(herf)
  })
}

const handleSizeChange = (data: any) => {
  params.value.pageSize = data
}
search(modelValue)

</script>
<style lang="scss" scoped>
.pageInfo-box {
  display: flex;
  justify-content: right;
  padding-top: 30px;
}
</style>
